package com.songcha.library_business.ui.dialog

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.songcha.library_business.bean.book.BookNetBean
import com.songcha.library_business.util.BusinessJumpUtil
import com.songcha.library_common.ui.dialog.CustomDialog
import com.songcha.library_common.util.GlideUtil
import com.songcha.library_common.util.dp2px
import com.songcha.library_business.R
import com.songcha.library_business.util.MajiaBaoUtil

class HomeBookRecommendDialog(context: Context,val book:BookNetBean):CustomDialog(context) {
    private var majiaName = "douyue"

    init {
        custom(0f)
        setWidth(280.dp2px())
        setCancelOnTouchOutside(false)
        setCanCancelable(false)
        majiaName = MajiaBaoUtil.getMajiaName()
    }

    override fun hasView(): Boolean {
        return true
    }

    override fun getView(root: ViewGroup): View? {

        val view = layoutInflater.inflate(R.layout.business_home_dialog_book_recommend,root,false)
        view.findViewById<ImageView>(R.id.business_iv_title).apply {
            if(majiaName != "douyue"){
                val lp = this.layoutParams
                lp.height = 68.dp2px()
                this.layoutParams = lp
            }
        }

        view.findViewById<ImageView>(R.id.business_iv_bg2).apply {
            if(majiaName != "douyue"){
                val lp = this.layoutParams
                lp.height = 241.dp2px()
                this.layoutParams = lp
            }
        }

        view.findViewById<ImageView>(R.id.business_iv_dialog_close).setOnClickListener {
            dismiss()
        }
        view.findViewById<ImageView>(R.id.business_iv_thumb).apply {
            GlideUtil.loadNetImage(this,book.cover)
        }
        view.findViewById<TextView>(R.id.business_tv_bookname).text = book.bookName
        view.findViewById<TextView>(R.id.business_tv_desc).text = book.description
        view.findViewById<LinearLayout>(R.id.business_ll_container).setOnClickListener {
            dismiss()
            BusinessJumpUtil.toBookDetail(book.bookId.toString())
        }

        return view
    }
}